package com.etrans.web.gps.business.checktask.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.etrans.web.gps.base.service.BaseService;
import com.etrans.web.gps.business.checktask.domain.AreaVO;
import com.etrans.web.gps.business.checktask.domain.EnterpriseVO;


/**
 * 业户信息管理Service
 * @author Tan
 *
 */
@Service
public class EnterpriseService extends BaseService{
	
	
	/**
	 * 根据ID查询业户信息
	 * @param enterpriseId
	 * @return
	 */
	public EnterpriseVO queryEnterpriseById(Integer enterpriseId) {
		//查询所有区域列表
		List<AreaVO> areaList = selectList("EnterpriseQusery.queryAreaTreesExtend",null);
		Map<String,String> areaMap = new HashMap<String,String>();
		for (AreaVO areaVO : areaList) {
			areaMap.put(areaVO.getFullId(), areaVO.getName());		
		}
		EnterpriseVO enterpriseVO = selectOne("EnterpriseQusery.queryEnterpriseById",enterpriseId);
		String areaName  = enterpriseVO.getAreaName();
		String fullId= enterpriseVO.getAreaFullId();
		if (fullId != null) {
			Integer lenth = fullId.length();
			if (lenth > 18) {
				String gParentFullId = fullId.substring(0, 8);
				String parentFullId = fullId.substring(0, 17);
				String gParentName = areaMap.get(gParentFullId) == null ? "" : areaMap.get(gParentFullId);
				String parentName = areaMap.get(parentFullId) == null ? "" : areaMap.get(parentFullId);
				areaName = gParentName+"-"+parentName+"-"+enterpriseVO.getAreaName();
				enterpriseVO.setAreaName(areaName);
			}else if (lenth > 9) {
				String parentFullId = fullId.substring(0, 8);
				String parentName = areaMap.get(parentFullId) == null ? "" : areaMap.get(parentFullId);
				areaName = parentName+"-"+enterpriseVO.getAreaName();
				enterpriseVO.setAreaName(areaName);
			}	
		}
		return enterpriseVO;
	}
	
	
	
	
	
	
	

	
}
